﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>在线邮件群发工具</title>

<link href="/static/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/static/DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/static/fckeditor/fckeditor.js"></script>
<script type="text/javascript">
//<!--
var nSum = 0;
{{template.nMailSum}} //预览时使用的邮件总数
var nCurrentMail = 0;

{{ template.titles }}
{{ template.contexts }}

var basepath = '/'  //修改这个为虚拟目录
window.onload = function()
{
	var oFCKeditor = new FCKeditor('fck_mail_body', '100%', '400');
	oFCKeditor.BasePath = "/static/fckeditor/";
	oFCKeditor.Value = '';
	oFCKeditor.ReplaceTextarea();
	Use_gdata();
	if (nSum > 0){
		 var context = document.getElementById('mailContext');
		context.innerHTML = arrContexts[0];
		var subject = document.getElementById('mailSubject');
		subject.innerHTML = arrTitles[0];
	}
}

function checkValue(isSaveTemplate)
{
	if (document.form1.txtMailSubject.value == '')
	{
		alert("邮件标题不能为空!");
		document.form1.txtMailSubject.focus();
		return false;
	}

	var oEditor = FCKeditorAPI.GetInstance('fck_mail_body');
	if (oEditor.GetXHTML(true) == '')
	{
		alert("邮件内容不能为空!");
		return false;
	}
	//以上为保存模版时必填内容

	if (isSaveTemplate)
	{
		if (document.form1.tempName.value == '')
		{
			alert("模版名不能为空");
			document.form1.tempName.focus();
			return false;
		}
        document.form1.btnSumit.disabled="disabled";
		return true;
	}
	if (document.form1.mainIndex.value == '')
	{
			alert("请指定邮箱所在列!");
			document.form1.mainIndex.focus();
			return false;
	}
	if (document.form1.checkOnTime.checked)
	{
		if (document.form1.txtDatetime.value == '')
		{
			alert("发送时间不能为空!");
			document.form1.txtDatetime.focus();
			return false;
		}
	}

	if (document.form1.chkGoogle.checked)
	{
		if (document.form1.gLogMail.value == '' ||
			document.form1.gPsw.value == '' ||
			document.form1.gSheetName.value == ''||
			document.form1.wksht_name.value == '')
		{
			alert("登录google信息不全!");
			return false;
		}
	}
	else if(document.form1.txtSendList.value == '')
	{
		alert("收件人不能为空!");
		document.form1.txtSendList.focus();
		return false;
	}
    //document.form1.btnSumit.disabled="disabled";
	return true;
}

function Use_gdata()
{
	if (document.form1.chkGoogle.checked)
	{
		document.form1.txtSendList.style.display = 'none';
		document.getElementById("divToMailListBox").style.display = 'none';
		document.getElementById("divGoogleBox").style.display = '';
	}
	else
	{
		document.getElementById("divToMailListBox").style.display = '';
		document.form1.txtSendList.style.display = '';
		document.getElementById("divGoogleBox").style.display = 'none';
	}
}
function saveToGoogle(obj){
	if (checkValue(false))
	{
		document.form1.action = basepath + "savetemplate/?action=google";
		document.form1.submit();
		//obj.disabled="disabled";
		return true;
	}
	else
	{
		return false;
	}
}
function saveTemplate(obj)
{
	if (checkValue(true))
	{
		document.form1.action = basepath + "savetemplate/?action=locad";
		document.form1.submit();
		//obj.disabled="disabled";
		return true;
	}
	else
	{
		return false;
	}
}
function readFromGoogle(obj){
	if (document.form1.gLogMail.value == '' ||
		document.form1.gPsw.value == '' ||
		document.form1.gSheetName.value == ''||
		document.form1.wksht_name.value == '')
	{
		alert("登录google信息不全!");
		return false;
	}
    else{
		document.form1.action = basepath + "readgdata/";
		document.form1.submit();
		//obj.disabled="disabled";
		return true;
    }
}
function onSendMail(){
	if (checkValue(false))
	{
		document.form1.action = basepath +  "smail/?action=smail";
		document.form1.submit();
		return true;
	}
	else{
		return false;
	}
}
//以下处理预览功能
function Preview()
{
	if (checkValue(false))
	{
		document.form1.action = basepath +  "smail/?action=preview";
		document.form1.submit();
		return true;
	}
	else{
		return false;
	}
}

function previewCloes()
{
	document.getElementById("tb_preview").style.display = 'none';
	return false;
}
function previewIndex()
{
	var nIndex = document.getElementById("previewIndex").value - 1;
	if	(nIndex < 0 || nIndex >= nSum){
		alert("指定邮件不存在！");
	}
	else{
		setPrevew(nIndex);
	}
	return false;
}
function setPrevew(nIndex)
{
	try{
		var context = document.getElementById('mailContext');
		context.innerHTML = arrContexts[nIndex];
		var subject = document.getElementById('mailSubject');
		subject.innerHTML = arrTitles[nIndex];
	}
	catch(err)
	{
	}
}

function next()
{
	if (++nCurrentMail >= nSum){
		nCurrentMail = nSum -1;
		 alert("已到达最后一封!");
	}else{
		setPrevew(nCurrentMail);
	}
	return false;
}

function previous()
{
	nCurrentMail--;
	if (nCurrentMail < 0){
		nCurrentMail = 0;
		alert("已到达第一封!");
	}else{
		setPrevew(nCurrentMail);
	}
	return false;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
</head>

<body>
<table width="100%" border="0" summary="">
  <tr>
  <form action="/smail/?action=smail" method="post" enctype="multipart/form-data" name="form1" id="form1" >
	<td align="left">
	  <table width="95%" border="1" cellspacing="1" cellpadding="1" >
		<tr>
		  <td width="19%" class="td_left"> 使用模版 </td>
		  <td width="57%" class="td_right"><select name="jumpMenu" class="td_right" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0);">
			<option value="/?key=0">可选择模版</option>
			<option value="/">空模版</option>
			{% for temp in templateList %}
			<option value="/?key={{temp.id}}">{{temp.name}}</option>
			{% endfor%}
					</select> &nbsp;&nbsp;&nbsp;&nbsp;
			<a href="/deltemplate/?key={{template.id}}" style="display:{{template.delete}}" onclick="return confirm('真的要删除吗,此操作不可撤消!')">删除本模版</a></td>
		  <td width="24%" class="td_right"> 欢迎 {{nickname}}| <a href="/logout/">注销</a></td>
		</tr>
	  </table>
	  <table width="95%" border="1" cellpadding="1" cellspacing="1"  >

		<tr >
		  <td colspan="2" class="td_center"><div  style="font-size:18px">GMail邮件群发工具</div></td>
		  </tr>
		 
		<tr>
		  <td class="td_left">默认回复邮箱</td>
			<td class="td_right">
			  <input name="reply_to" type="text" id="reply_to" value="{{template.reply_to}}" size="40" />
			  <span class="STYLE1">*</span> </td>
		</tr>
		<tr>
		  <td class="td_left">发件人Google帐号</td>
			<td class="td_right">
			  <input name="sender" type="text" id="sender" value="{{template.sender}}" size="40" disabled="disabled" />
			  <span class="STYLE1">	* </span>
			  <input type="checkbox" name="chkSendmyself" id="chkSendmyself" {{template.isSendMyself}} />每一封同时发送给自己			</td>
		</tr>
		<tr>
		  <td class="td_left"><p>收件人邮箱列表</p>
			<p>
			  <label>
			  <input name="chkGoogle" type="checkbox" id="chkGoogle"  onclick="Use_gdata()" checked="checked" {{template.usedgdata}}/>
			  使用google电子表格数据</label>
			</p></td>
			<td class="td_right">格式规定为每行一收件人，必需包含邮箱地址，<br>
			<div id="divToMailListBox" >
			<span class="STYLE1">要替换文字使用英文竖线|如(</span> mail@mial.com<span class="STYLE1">|</span> 姓名<span class="STYLE1"> ) 或 'tab'键隔开.</span><br />
			  <textarea name="txtSendList" id="txtSendList" cols="80" rows="6">{{template.mail_list}}</textarea>
			  </div>
			  <div id="divGoogleBox" >
			  <table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr> 请保证文件在google服务器上<span class="STYLE1">文件名唯一</span>性.并确保格式一致<br>
	<td width="20%" class="td_left">google登录邮箱</td>
	<td width="80%" class="td_right">
	<label class="STYLE1"><input type="text" name="gLogMail" id="gLogMail" value="{{template.glogin_mail}}" size="40" />*</label></td>
  </tr>
  <tr>
	<td class="td_left">密码</td>
	<td class="td_right"><label>
	  <input type="password" name="gPsw" id="gPsw" size="40" value="{{template.gPsw}}" />
	  <span class="STYLE1">	*</span></label></td>
    </tr>
  <tr>
	<td class="td_left">表格文件名</td>
	<td class="td_right"><label>
	  <input type="text" name="gSheetName" id="gSheetName" size="40"  value="{{template.gFileName}}"/>
	  <span class="STYLE1">*</span></label></td>
    </tr>
  <tr>
	<td class="td_left">工作表名称</td>
	<td class="td_right">
	<label>
     <input name="wksht_name" type="text" id="wksht_name"  value="{{template.wksht_name}}"/>
     (</label>注：大小写敏感)
	<input name="btnSumit4" style="display:none" type="button"  id="btnSumit4" onclick="return readFromGoogle(this);" value="从Google中读模版" /></td>
    </tr>
</table>
</div>
			邮件地址所在（序号1，2，3....）列：<input name="mainIndex" type="text" id="mainIndex" size="10" value="{{template.nColMail}}">			<span class="STYLE1">*</span></td>
		</tr>
		<tr>
		  <td class="td_left">自定义宏</td>
			<td class="td_right"> <span class="STYLE1">宏只能使用英文逗号(',')号隔开,每个宏对应一列数据.请定义复杂名称宏。
			<br />
			<textarea name="txtMacroList" id="txtMacroList" cols="80" rows="4" >{{template.macro}}</textarea></td>
		 </tr>
		<tr>
		  <td class="td_left">邮件标题</td>
			<td class="td_right" >
				<input name="txtMailSubject" type="text" id="txtMailSubject" value="{{template.subject}}" size="80" />
				<span class="STYLE1">*</span></td>
		  </tr>
		  <tr style="display:none">
			<td class="td_left">发送选项</td>
		  <td class="td_right">定时
			<input name="checkOnTime" type="checkbox" id="checkOnTime"  {{template.isSendOntime}}  disabled="disabled"/>
			时间：<input name="txtDatetime" id="txtDatetime" class="Wdate" onfocus="new WdatePicker(this,'%Y-%M-%D %h:%m:%s',true)" MINDATE="#Year#-#Month#-#Day#" value="{{template.time}}"  disabled="disabled" >
			(GAE上不支持该功能 )</td>
		  </tr>
		  <tr>
			<td class="td_left">内容(<span class="STYLE1">*</span>)</td>
		  <td ><span class="">
			<textarea name="fck_mail_body" cols="80" rows="4" id="fck_mail_body" >{{fck.value}}</textarea>
		  </span></td>
		  </tr>
		  <tr>
			<td class="td_left">模版名称</td> 
		  <td class="td_right">
			<input name="tempName" type="text" id="tempName" />
			<input name="btnSumit2" type="button" id="btnSumit2" onclick="return saveTemplate();" value="保存为模版"  />
		（只在保存为模版时填写）
		<input name="btnSumit3" type="button"  id="btnSumit3" style="display:none" onclick="return saveToGoogle(this);" value="模版保存到Google" /></td>
				 </tr>
		  <tr >
			<td class="td_left" >附件</td>
			<td class="td_right"><label>
			  <input name="NewFile" type="file" id="NewFile" value="{{template.upload}}"  disabled="disabled"/>
(暂不支持该功能 )</label></td>
		  </tr>
		  <tr>
			<td colspan="2" align="center" class="td_center">
			  <label>
			  <input type="submit" name="btnSumit" id="btnSumit" value="发送邮件" onclick="return onSendMail();"/>
			  </label> <input type="button" name="btnPreview" id="btnPreview" onclick="return Preview();"  value="预览" /> <label>
			  <input type="reset" name="btnReset" id="btnReset" value="重置" />
			</label></td>
		   </tr>
		</table>
	  </td>
	  </form>
  </tr>
</table>
<table width="100%" border="1" cellspacing="1" cellpadding="1" id="tb_preview" >
  <tr>
	<td colspan="2">&nbsp;</td>
  </tr>
  <tr>
	<tr>
	<td colspan="2" align="center" class="td_center"><a href="#" onclick="return previous();">上一封</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#" onclick="return next();">下一封</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#" onclick="return previewCloes(); ">关闭预览</a>

	  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	  指定预览 <input name="previewIndex" type="text" id="previewIndex" size="4" /> <a href="#" onclick="return previewIndex();">预览</a>	</td>
  </tr>
	<td width="14%" class="td_left">标题</td>
	<td width="86%">&nbsp; <div name="mailSubject" id="mailSubject" ></div> </td>
  </tr>
  <tr>
	<td class="td_left">内容</td>
	<td>&nbsp;<div id="mailContext" > </div></td>
  </tr>
  <tr>
    <td class="td_left">google数据</td>
 
    <td>{{template.gdata}}&nbsp;</td>
 
  </tr>
</table>
<table width="100%" style="font-size:12px;">
<tr >
	<td width="100%" align="center"> <img src="http://code.google.com/appengine/images/appengine-silver-120x30.gif" 
alt="由 Google App Engine 强力驱动" />  Power by TooNTonG@163.com 2009-07-01</td>
</tr>
</table>
</body>
</html>
